<div>
    <form class="layui-form form" lay-filter="globalTypeForm">
        <div class="layui-form-item">
            <label class="layui-form-label">父节点:</label>
            <div class="layui-input-block">
                <input type="text" id="parentName" name="parentName" lay-verify="parentName" value="${parentName}" autocomplete="off" class="layui-input" readonly>
                <input type="hidden" id="isRoot" name="isRoot"  value="${isRoot}" class="layui-input">
                <input type="hidden" id="parentId" name="parentId"  value="${parentId}" class="layui-input">
                <input type="hidden" id="typeId" name="typeId"  value="${typeId}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称:*</label>
            <div class="layui-input-block">
                <input type="text" id="typeName" name="typeName" value="${globalType.typeName}" lay-verify="required" autocomplete="off" placeholder="请输入名称" class="layui-input" maxlength="50">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">节点Key:*</label>
            <div class="layui-input-block">
                <input type="text" id="nodeKey" name="nodeKey" lay-verify="required" value="${globalType.nodeKey}" autocomplete="off" placeholder="请输入节点Key" class="layui-input" maxlength="50">
            </div>
        </div>
        <div id="dicTypeDiv" style="display:none">
            <div class="layui-form-item">
                <label class="layui-form-label">字典类型:</label>
                <div class="layui-input-block">
                    <div id="selectDicType">
                        <input type="radio" name="type" id="tiled" lay-filter="type" value="0" title="平铺"/>
                        <input type="radio" name="type" lay-filter="type" value="1" title="树形" checked/>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item" style="text-align: center;">
            <a lay-submit lay-filter="listAddNodeBtn" class="layui-btn btn-n">提交</a>
            <button class="layui-btn cancelFrom layui-btn-danger">取消</button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'setter', 'jquery', 'table','commons'], function () {
        var form = layui.form
        , layer = layui.layer;
        var table = layui.table;
        var setter = layui.setter;
        var $ = layui.$;
        var commons = layui.commons;
        var isGlobalType = "${isGlobalType}";

        var isShow = "${isShow}";
        if(isShow){
            $("#dicTypeDiv").show();
        }

        //设置初始单选值
        var type = "${type}";
        form.val("globalTypeForm", {
            'type': type
        })

        form.on("submit(listAddNodeBtn)",function () {
            var typeName = $("input[name='typeName']").val();
            var nodeKey = $("input[name='nodeKey']").val();
            var isRoot = $("input[name='isRoot']").val();
            var parentId = $("input[name='parentId']").val();
            var typeId = $("input[name='typeId']").val();
            var type = $("input[name='type']:checked").val();
            var nodeCode = $("#nodeCode").val();
            var nodeCodeType = $("input[name='nodeCodeType']").val();
            var data = {"isRoot":isRoot,"typeName":typeName,"nodeKey":nodeKey,"parentId":parentId,"typeId":typeId,"type":type,"nodeCode":nodeCode,"nodeCodeType":nodeCodeType};
            if(typeName == ''){
                layer.msg('名称为必填项!', {icon: 5,ime:1000,})
                return false;
            }
            if(nodeKey == ''){
                layer.msg('节点key为必填项!', {icon: 5,ime:1000,})
                return false;
            }
            $.ajax({
                url: serverPath.systemPath + setter.sysLinkPath + "globalType/add",
                type: "POST",
                dataType: 'json',
                data: data,
                success: function (res) {
                    layer.alert(res.msg);
                    if(isGlobalType){
                        layui.reloadGlobalTypeRes();
                    }
                    if (commons._filterRecord(res)) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        // window.parent.layer.alert(data.msg, function () {
                        //     commons.bulletWindow(window.parent.index);
                        //     if(isShow){
                        //         window.parent.parent.layui.index.render();
                        //     }else{
                        //         window.parent.layui.index.render();
                        //     }
                        // });
                    }
                    // else {
                    //     window.parent.layer.alert(res.msg);
                    // }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("保存失败！" + XMLHttpRequest.status);
                }
            });
        })

        $(".cancelFrom").click(function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name))
        });


        //自动生成别名
        $("#typeName").change(function () {
            var str = $(this).val();
            if (str == "") return;
            var arrRslt = component.chineseToPinyinAlias(str);
            $("#nodeKey").val(arrRslt[0]);
        });

    })
</script>
<style scoped>
    .form {
        width: 404px;
        overflow: auto;
        margin-top: 10px;
        padding:10px 10px;
    }
    #LAY_app{
        overflow: hidden;
    }
    .layui-form-select dl{
        max-height: 150px;
    }
</style>